Repository navigation
fix(cache-ledger): attribute tail-append misses to provider-side, not seam suspects (#2059) - #2061
Conversation
… seam suspects (#2059) detectSeam's upstream-side test demanded the whole body match byte-for-byte (lcpBytes >= cur.length), which a growing conversation never satisfies because each turn appends new messages at the tail. So the common 'tail append + upstream did not serve its cache' case fell through to a false seam-suspect (CACHE SEAM), while the stronger signal seamLcp already computes -- msgIndex == prevMsgs, i.e. the previous request's entire message list survives byte-identically as this request's prefix -- went unused. When msgIndex === prevMsgs and curMsgs > prevMsgs (a pure tail growth) and both bodies are within SEAM_BODY_CAP (a truncated body parses to zero messages and would fake the msgIndex == prevMsgs == 0 signature), book the miss as providerSideMisses instead of seamSuspects. 0 < msgIndex < prevMsgs (real mid-history break) and msgIndex == 0 (head break) keep their original seam-suspect classification, pinned by tests. No forwarded bytes change -- pure observation layer. PROVIDER-SIDE MISS report wording updated to cover both the exact-resend and tail-append cases.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2106-pr.2061.e8d23b4This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2061.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…d criterion (#2059) Labeled in-passing fix from review of this PR: after the tail-append reclassification, providerSideMisses also covers samples whose bodies were NOT fully byte-stable (message list preserved, tail appended), so the old 'wire was byte-stable' wording in the web-panel tip (zh+en) and the providerSideMisses doc comment no longer matched the code fact. Updated to state the actual criterion.
[bot] 🏷 Review complete — verdict up front: code is correct, tests are real, CI fully green; but this PR duplicates #2060 (opened by @ADkun 2 minutes earlier, same issue) and is a strict subset of its scope. Owner needs to pick one; I have closed neither. Details below. 结构化七问
验证证据
|
| 维度 | #2061(本 PR) | #2060(@ADkun) |
|---|---|---|
| 核心修复 | ✅ | ✅(等价) |
| 对既有 exact-resend 臂也加 under-cap 守卫 | ❌ 不动 | ✅ ——额外行为变更:超 cap 的字节全同对从 providerSideMisses 回退到 seamSuspects(「不在截断证据上断言」,保守方向;属产品判断,需 owner 明示签核) |
| web 面板 i18n 措辞同步 | ✅(本 review 补的 d11fa207) |
✅ |
| 同消息数情形(消息列表相同、差异在 messages 之外如 tools/system 漂移) | 仍留 seam-suspect(更保守) | 也归 provider-side(其 helper 不要求 curMsgs > prevMsgs) |
| 基线 | 当前 master | 落后 master,合并前需 rebase |
| CI | 15/15 绿 | 15/15 绿 |
按机制优先原则(owner policy 2026-10-01),「SEAM_BODY_CAP 截断扭曲归因取证」是一个机制族,#2060 覆盖得更完整;但按外部贡献者保护政策,我不会关闭或替代 @ADkun 的 PR。建议二选一:① 要最小行为差、最快落地 → 合本 PR(已含措辞同步);② 要机制族完整处理(含 over-cap exact-resend 守卫)→ rebase 后合 #2060 并对那一处额外行为变更显式签核,本 PR 随之关闭。
另记录一个既有残留(非本 PR 引入、不扩本 PR 范围,按机制族留作 checklist 项):cur 体超 cap 而 prev 正常时,截断侧解析为 0 条消息会命中既有的 rewind 分支(curMsgs(0) < prevMsgs),把「相邻轮次体积暴涨」误标为 HISTORY REWOUND——master 上已存在,需要的话另行立项。
收工判定:本 PR 自身可合(auto-merge gate 各项满足,纯 fix、回归测试齐、绿在最新 master 之上);最终合并哪个由 owner 在 #2060/#2061 之间拍板。
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.11-master.2be41f9 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Summary
Fixes #2059.
detectSeam(src/cache-ledger.ts) separates "upstream-side" cache misses from "local mid-history prefix breaks" before booking an unexplained residual as a seam-suspect. Its upstream-side test waslcpBytes >= cur.length— i.e. the entire outbound body must match the previous request byte-for-byte. But a conversation appends new messages at the tail every turn, solcpBytescan never reachcur.length; the condition almost never held. Result: the most ordinary "tail append + upstream did not serve its cache" event was booked asseamSuspectsand surfaced as⚠ CACHE SEAM (suspected mid-history prefix breaks).The stronger, already-computed signal went unused:
seamLcpreturnsmsgIndex/prevMsgs.msgIndex === prevMsgsmeans the previous request's entire message list survives byte-identically as this request's prefix and only the tail grew — no prefix break exists. That is provider-side (TTL expiry / eviction / relay node rotation), not a rebuild seam.Change
In
detectSeam, after the exact-resend check, add: whenmsgIndex === prevMsgs && curMsgs > prevMsgs(a pure tail growth) and both bodies are withinSEAM_BODY_CAP, book the miss intoproviderSideMisses/providerSideMissedinstead ofseamSuspects.The cap guard is load-bearing: a body truncated at
SEAM_BODY_CAPfailsJSON.parseinsideseamLcp.msgsOf→ zero messages → would fake themsgIndex === prevMsgs === 0signature; truncated pairs therefore keep the old (conservative) seam-suspect path.prevMsgs > 0additionally keeps an empty prior list out.Untouched, and pinned by tests:
0 < msgIndex < prevMsgs(real mid-history break) → still seam-suspectmsgIndex == 0(head break) → still seam-suspectlcpBytes >= cur.length) → still provider-sidecurMsgs < prevMsgs) → still HISTORY REWOUNDNo forwarded bytes change — pure observation layer (§7.3 root-cause-first: fix the attribution at the decision point, don't filter payload in transit).
⚠ Behavior change (attribution bucketing + report wording)
This intentionally changes how PAST tail-append misses are bucketed and worded:
agg.seamSuspects, shown under⚠ CACHE SEAM (suspected mid-history prefix breaks)agg.providerSideMisses, shown under▲ PROVIDER-SIDE MISSPROVIDER-SIDE MISSheader / textWhy: the old bucketing mis-attributed the dominant class of large misses as rebuild seams when they were upstream TTL/eviction/rotation. Per the issue's local ledger (289 sessions), 78/87 large-miss events (89.7%) satisfied
msgIndex == prevMsgs— ~5.7M input tokens — all previously shown asCACHE SEAM. This moves them to the correct bucket. Genuine mid-history / head breaks are unaffected (pinned by tests). No closure math changes — only which diagnostic bucket the residual lands in.Existing test
seam events are bounded (ring keeps the last 8)updated: its first transition (["a"] -> ["a","v0"]) is a pure tail append, now provider-side, soseamSuspectsgoes 12 → 11 andproviderSideMissesgains 1. The ring-cap assertion is unchanged.Config surface
None. No new config key, env var, CLI flag, or report field. Reuses the existing
providerSideMisses/providerSideMissedcounters and the existingPROVIDER-SIDE MISSreport section.SEAM_BODY_CAP/SEAM_EVENTS_CAPconstants unchanged.Tests
New in
tests/cache-seam-detector.test.ts:0 < msgIndex < prevMsgs) stays seam-suspectmsgIndex == 0) stays seam-suspectVerification on rebased master (v0.1.182): typecheck clean, build green, targeted suites
cache-seam-detector+issue1891-seam-nobaseline+cache-ledger= 57/57 pass. Full regression left to CI.